home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / ogrid100.zip / GLVIEWS.PAS < prev    next >
Pascal/Delphi Source File  |  1994-12-29  |  13KB  |  437 lines

  1. {********************************************************************
  2.  
  3.   OOGrid Library(TM) v1.0 for Borland/Turbo Pascal (Real Mode/TV)
  4.   Copyright (C) 1994 by Arturo J. Monge
  5.   Portions Copyright (C) 1989,1990 Borland International, Inc.
  6.  
  7.   OOGrid Library(TM) Views Unit:
  8.     Implements three TView's descendants used by the TSpreadSheet object
  9.     and also defines the record variables used by the SetData and GetData
  10.     methods of the dialogs used by TSpreadSheet.
  11.  
  12.   Copyright (C) 1994 by Arturo J. Monge
  13.  
  14.   Last Modification : December 29th, 1994
  15.  
  16. *********************************************************************}
  17.  
  18. {$O+,F+,X+}
  19.  
  20. unit GLViews;
  21.  
  22. {****************************************************************************}
  23.                                  interface
  24. {****************************************************************************}
  25.  
  26. uses Objects, Dialogs, Drivers, Views, GLEquate;
  27.  
  28. type
  29.  
  30.   PSheetInputLine = ^TSheetInputLine;
  31.   TSheetInputLine = OBJECT(TInputLine)
  32.   { An input line that can be inserted in a TSpreadSheetWindow object in
  33.     modal state.  It maps to the color palette of the TSpreadsheetWindow
  34.     object and handles kbEnter, kbEsc, kbUp and kbDown by ending the modal
  35.     state of the view }
  36.       EndState : Word;
  37.     constructor Init(AMaxLen: Integer);
  38.     procedure EndModal(Command: Word); virtual;
  39.     function Execute: Word; virtual;
  40.     function GetPalette: PPalette; virtual;
  41.     procedure HandleEvent(var Event: TEvent); virtual;
  42.     procedure SetState(AState: Word; Enable: Boolean); virtual;
  43.   end; {...TSheetInputLine }
  44.  
  45. const
  46.  
  47. { TSheetInputLine palette }
  48.  
  49.   CSheetInputLine = #9#9#10#11;
  50.  
  51. { CSheetInputLine palette layout }
  52.  
  53.   { 1 = Passive }
  54.   { 2 = Active }
  55.   { 3 = Arrow }
  56.   { 4 = Selected }
  57.  
  58. type
  59.  
  60.   PLimScrollBar = ^TLimScrollBar;
  61.   TLimScrollBar = object(TScrollBar)
  62.   { A TScrollBar's descendant that allows the definition of a display subrange.
  63.     This is particularly useful if the TScroller object that owns the
  64.     scrollbar has a very broad scrolling range (for example, 32767 columns).
  65.     In this case, a normal TScrollBar object would be of no use at all,
  66.     because one click in an arrow would move the scroller more than 1000
  67.     columns. TLimScrollBar lets you define a smaller scrolling range, making
  68.     it more useful than a TScrollBar }
  69.       OldValue     : Word;
  70.       DisplayLimit : Word;
  71.     constructor Init(var Bounds: TRect; ADisplayLimit: Integer);
  72.     function Change: Integer;
  73.     procedure Draw; virtual;
  74.     procedure HandleEvent(var Event: TEvent); virtual;
  75.     constructor Load(var S: TStream);
  76.     procedure Store(var S: TStream);
  77.   end; {...TLimScrollBar }
  78.  
  79.  
  80.   PMessageLine = ^TMessageLine;
  81.   TMessageLine = object(TView)
  82.   { Displays the string stored in the StatusMessage attribute.  This object
  83.     is used to display status line messages }
  84.       StatusMessage : String[79];
  85.     constructor Init (Bounds:TRect; AMessage:String);
  86.     procedure Draw; virtual;
  87.   end; {...TMessageLine }
  88.  
  89. var
  90.   MessageLine : PMessageLine;
  91.   { Global variable used to display messages at the bottom of the screen }
  92.  
  93. var
  94.  
  95. { Global record-type variables used with the GetData and SetData methods
  96.   of TSpreadsheet's dialogs }
  97.  
  98.   RChangeHeader : record
  99.   { Used by the ChangeHeader dialog }
  100.     NewHeader : String[80]; {Inputline}
  101.   end; {...RChangeHeader }
  102.  
  103.   RChangeWidth : record
  104.   { Used by the ChangeWidth dialog }
  105.     NewWidth : String[10]; {Inputline}
  106.   end; {...RChangeWidth }
  107.  
  108.   RFormat : record
  109.   { Used by the FormatCell dialog }
  110.     Justification : Word; {RadioButtons}
  111.     DecimalPlaces : String[1]; {Inputline}
  112.     CurrencyChar : String[1]; {Inputline}
  113.     NumberFormat : Word; {Checkboxes}
  114.   end; {...RFormat }
  115.  
  116.   RGoToCell : record
  117.   { Used by the GoTo dialog }
  118.     NewCell : String[10]; {Inputline}
  119.   end; {...RGoToCell }
  120.  
  121.   RCopyFormulas : record
  122.   { Used by the CopyFormulas dialog }
  123.     CopyFormulas : Word; {Checkboxes}
  124.   end; {...RCopyFormulas }
  125.  
  126.   RPrint : record
  127.   { Used by the Print dialog }
  128.     PrintTo : Word; {RadioButtons}
  129.     PrintSize : Word; {RadioButtons}
  130.     PrintRows : Word; {RadioButtons}
  131.     PrintColumns : Word; {RadioButtons}
  132.     TopMargin : String[3]; {Inputline}
  133.     BottomMargin : String[3]; {Inputline}
  134.     LeftMargin : String[3]; {Inputline}
  135.     RightMargin : String[3]; {Inputline}
  136.     Other : Word; {Checkboxes}
  137.     PageRows : String[3]; {Inputline}
  138.     NormalCols : String[3]; {Inputline}
  139.     CondensedCols : String[3]; {Inputline}
  140.   end; {...RPrint }
  141.  
  142.   RSortInfo : record
  143.   { Used by the Sort dialog }
  144.     FirstKey : String[80]; {Inputline}
  145.     FirstKeyOrder : Word; {RadioButtons}
  146.     SecondKey : String[80]; {Inputline}
  147.     SecondKeyOrder : Word; {RadioButtons}
  148.     ThirdKey : String[80]; {Inputline}
  149.     ThirdKeyOrder : Word; {RadioButtons}
  150.   end; {...RSortInfo }
  151.  
  152. function DisplayMessage (AMessage:String): Boolean;
  153. { Displays a message at the bottom of the screen }
  154. procedure EraseMessage;
  155. { Erases a message that was displayed using DisplayMessage }
  156. procedure RegisterGLViews;
  157. { Register the unit's objects }
  158.  
  159. const
  160.   RLimScrollBar : TStreamRec = (
  161.      ObjType : stRLimScrollBar;
  162.      VmtLink : Ofs(TypeOf(TLimScrollBar)^);
  163.      Load    : @TLimScrollBar.Load;
  164.      Store   : @TLimScrollBar.Store
  165.   );
  166.  
  167.   RSheetInputLine : TStreamRec = (
  168.      ObjType : stRSheetInputLine;
  169.      VmtLink : Ofs(TypeOf(TSheetInputLine)^);
  170.      Load    : @TSheetInputLine.Load;
  171.      Store   : @TSheetInputLine.Store
  172.   );
  173.  
  174. {****************************************************************************}
  175.                                implementation
  176. {****************************************************************************}
  177.  
  178. uses App;
  179.  
  180. {** Unit's Register procedures **}
  181.  
  182. procedure RegisterGlViews;
  183. begin
  184.   RegisterType(RLimScrollBar);
  185.   RegisterType(RSheetInputLine);
  186. end; {...RegisterGLViews }
  187.  
  188.  
  189. {** DisplayMessage function **}
  190.  
  191. function DisplayMessage (AMessage:String): Boolean;
  192. var
  193.   R : TRect;
  194. begin
  195.   DisplayMessage := False;
  196.   Application^.GetExtent(R);
  197.   R.A.Y := R.B.Y - 1;
  198.   if MessageLine <> NIL then
  199.     begin
  200.       MessageLine^.StatusMessage := ' ' + AMessage;
  201.       MessageLine^.Draw;
  202.     end {...if MessageLine <> NIL }
  203.   else
  204.     begin
  205.       MessageLine := New(PMessageLine, Init(R, AMessage));
  206.       if MessageLine^.Valid(cmValid) = True then
  207.         begin
  208.           Application^.Insert(MessageLine);
  209.           DisplayMessage := True;
  210.         end {...if MessageLine^.Valid(cmValid) = True }
  211.       else
  212.         MessageLine := NIL;
  213.     end; {...if/else }
  214. end; {...DisplayMessage }
  215.  
  216.  
  217. {** EraseMessage procedure **}
  218.  
  219. procedure EraseMessage;
  220. begin
  221.   if MessageLine <> NIL then
  222.     Dispose(MessageLine , Done);
  223.   MessageLine := NIL;
  224. end; {...EraseMessage }
  225.  
  226.  
  227. {** TLimScrollBar **}
  228.  
  229. constructor TLimScrollBar.Init(var Bounds: TRect; ADisplayLimit: Integer);
  230. begin
  231.   TScrollBar.Init(Bounds);
  232.   DisplayLimit := ADisplayLimit;
  233. end; {...TLimScrollBar.Init }
  234.  
  235. function TLimScrollBar.Change: Integer;
  236. { Returns the amount of change in the scrollbar position }
  237. begin
  238.   Change := Value - OldValue;
  239. end; {...TLimScrollBar.Change }
  240.  
  241. procedure TLimScrollBar.Draw;
  242. { Draws the scrollbar using a virtual max value }
  243. var
  244.   RealMax   : Integer;
  245.   RealValue : Word;
  246. begin
  247.   RealMax := Max;
  248.   RealValue := Value;
  249.   Max := DisplayLimit;
  250.   If Value > DisplayLimit then
  251.     Value := DisplayLimit;
  252.   TScrollBar.Draw;
  253.   Max := RealMax;
  254.   Value := RealValue;
  255. end; {...TLimScrollBar.Draw }
  256.  
  257. procedure TLimScrollBar.HandleEvent(var Event: TEvent);
  258. var
  259.   Mouse       : TPoint;
  260.   MousePos    : Byte;
  261.   BarSize     : Byte;
  262.   RealValue   : Word;
  263.   RealMax     : Integer;
  264.   SendChanged : Boolean;
  265.  
  266.     function GetMouseRelativePos(MousePos, Size: Byte): Integer;
  267.     var
  268.       MousePoint : Real;
  269.     begin
  270.       MousePoint := (DisplayLimit / (Size - 3)) * MousePos;
  271.       GetMouseRelativePos := Trunc(MousePoint);
  272.     end; {...GetMouseRelativePos }
  273.  
  274. begin
  275.   OldValue := Value;
  276.   if Event.What = evMouseDown then
  277.   begin
  278.     if MouseInView(Event.Where) then
  279.     begin
  280.       MakeLocal(Event.Where, Mouse);
  281.       if ((Mouse.X <> 0) and (Mouse.X < Pred(Size.X))) or
  282.          ((Mouse.Y <> 0) and (Mouse.Y < Pred(Size.Y))) then
  283.         begin
  284.           if Mouse.Y = 0 then
  285.             begin
  286.               MousePos := Mouse.X;
  287.               BarSize := Size.X;
  288.             end {...if Mouse.Y = 0 }
  289.           else
  290.             begin
  291.               MousePos := Mouse.Y;
  292.               BarSize := Size.Y;
  293.             end; {...if/else }
  294.           RealValue := Value;
  295.           RealMax := Max;
  296.           Max := DisplayLimit;
  297.           if (Value > DisplayLimit) and
  298.              (GetMouseRelativePos(MousePos, BarSize) >= DisplayLimit) then
  299.             begin
  300.               Value := DisplayLimit;
  301.               TScrollBar.HandleEvent(Event);
  302.               if (Value = DisplayLimit) and
  303.                  (RealValue > DisplayLimit) then
  304.               begin
  305.                 DrawView;
  306.                 Message (Owner, evBroadCast, cmScrollBarChanged, @Self);
  307.               end; {...if (Value = DisplayLimit) and ... }
  308.             end {...if (Value > DisplayLimit) and ... }
  309.           else if (Value > DisplayLimit) then
  310.             begin
  311.               repeat
  312.                 if Value <= PgStep then
  313.                   Value := 1
  314.                 else
  315.                   Value := Value - PgStep;
  316.                 DrawView;
  317.                 Message (Owner, evBroadCast, cmScrollBarChanged, @Self);
  318.               until (not MouseEvent(Event, evMouseAuto)) or (Value = 1);
  319.             end {...else if (Value > DisplayLimit) }
  320.           else
  321.             TScrollbar.HandleEvent(Event);
  322.             Max := RealMax;
  323.         end {...if ((Mouse.X <> 0) and (Mouse.X < Pred(Size.X))) or ... }
  324.       else
  325.         TScrollBar.HandleEvent(Event);
  326.     end; {...if MouseInView(Event.Where) }
  327.   end; {...if Event.What = evMouseDown }
  328. end; {...TLimScrollBar.HandleEvent }
  329.  
  330.  
  331. constructor TLimScrollBar.Load(var S: TStream);
  332. { Reads the object from a stream }
  333. begin
  334.    TScrollBar.Load(S);
  335.    S.Read(OldValue, SizeOf(OldValue));
  336.    S.Read(DisplayLimit, SizeOf(DisplayLimit));
  337. end; {...TLimScrollBar.Load }
  338.  
  339.  
  340. procedure TLimScrollBar.Store(var S: TStream);
  341. { Writes the object to a stream }
  342. begin
  343.    TScrollBar.Store(S);
  344.    S.Write(OldValue, SizeOf(OldValue));
  345.    S.Write(DisplayLimit, SizeOf(DisplayLimit));
  346. end; {...TLimScrollBar.Store }
  347.  
  348.  
  349. {** TMessageLine **}
  350.  
  351. constructor TMessageLine.Init(Bounds:TRect; AMessage:String);
  352. begin
  353.   TView.Init(Bounds);
  354.   StatusMessage := ' '+AMessage;
  355. end; {...TMessageLine.Init }
  356.  
  357. procedure TMessageLine.Draw;
  358. { Displays the message within the bounds of the view using the color in
  359.   the 2nd entry of the application's palette (Normal Text) }
  360. var
  361.   B : TDrawBuffer;
  362.   C : Byte;
  363. begin
  364.   C := GetColor(2);
  365.   MoveChar(B, ' ', C, Size.X);
  366.   MoveStr(B, StatusMessage, C);
  367.   WriteLine(0, 0, Size.X, 1, B);
  368. end; {...TMessageLine.Draw }
  369.  
  370.  
  371. {** TSheetInputLine **}
  372.  
  373. constructor TSheetInputLine.Init(AMaxLen: Integer);
  374. var
  375.   R : TRect;
  376. begin
  377.   R.Assign(0,0,0,0);
  378.   TInputLine.Init(R, AMaxLen);
  379. end; {...TSheetInputLine.Init }
  380.  
  381. procedure TSheetInputLine.EndModal(Command: Word);
  382. begin
  383.   EndState := Command;
  384. end; {...TSheetInputLine.EndModal }
  385.  
  386. function TSheetInputLine.Execute: Word;
  387. { Allows modal execution of the inputline }
  388. var
  389.   E: TEvent;
  390. begin
  391.   EndState := 0;
  392.   repeat
  393.     GetEvent(E);
  394.     HandleEvent(E);
  395.   until EndState <> 0;
  396.   Execute := EndState;
  397. end; {...TSheetInputLine.Execute }
  398.  
  399. function TSheetInputLine.GetPalette: PPalette;
  400. const
  401.   NewPalette : string[Length(CSheetInputLine)] = CSheetInputLine;
  402. begin
  403.   GetPalette := @NewPalette;
  404. end; {...TSheetInputLine.GetPalette }
  405.  
  406. procedure TSheetInputLine.HandleEvent(var Event: TEvent);
  407. var
  408.   EmptyString : String;
  409. begin
  410.   TInputLine.HandleEvent(Event);
  411.   case Event.What of
  412.     evKeyDown :
  413.     begin
  414.       case Event.KeyCode of
  415.         kbEnter, kbUp, kbDown : EndModal(cmOk);
  416.         kbEsc   :
  417.           begin
  418.             EmptyString := '';
  419.             SetData(EmptyString);
  420.             EndModal(cmCancel);
  421.           end; {...case Event.KeyCode of kbEsc }
  422.       end; {...case Event.KeyCode }
  423.       ClearEvent(Event);
  424.     end; {...case Event.What of evKeyDown }
  425.   end; {...case Event.What }
  426. end; {...TSheetInputLine.HandleEvent }
  427.  
  428. procedure TSheetInputLine.SetState(AState: Word; Enable: Boolean);
  429. begin
  430.   TView.SetState(AState, Enable);
  431.   DrawView;
  432. end; {...TSheetInputLine.SetState }
  433.  
  434. begin
  435.   MessageLine := NIL;
  436. end. {...TSViews unit }
  437.